package edu.sctu.fengleilin.month06.day150628.SecondPractice;


import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user09 on 2015/6/29.
 */
public class SecondUrlThread {

    public void run() {
        try {

            URL url = new URL("http://api.ii.com.cn/goods/apprec");
            URLConnection connection = url.openConnection();

            InputStream is = connection.getInputStream();//获取connection的字节数据
            InputStreamReader isr = new InputStreamReader(is,"UTF-8");//将字节流转换为字符流
            BufferedReader br = new BufferedReader(isr);//获取connection的字符流


            String Line=null;
            StringBuilder builder = new StringBuilder();
            while ((Line = br.readLine()) != null){
                builder.append(Line);
            }

            FileWriter fw = new FileWriter(new File("D://json//json.txt"));//保存
            fw.write(builder.toString());

            fw.close();
            br.close();
            isr.close();
            is.close();

            System.out.println(builder.append(Line));

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new SecondUrlThread().run();
    }

}
